/** ver: 0.1, date 19-12-2007 by Jeroen W
 * 23-12-2007 - Jeroen S - Added some initial methods
 * 27-12-2007 - Jeroen S - Further updates to paintComponent
 * ver 0.4, dat 2 jan 2008 by Jeroen S
 * Activate graphics; minor related fixes
 * ver 0.5, dat 2 jan 2008 by Jeroen S
 * Solve state colours
 * ver 0.6, dat 2 jan 2008 by Jeroen S
 * Coloured squares made optional
 * ver 0.7, dat 03-01-2008 by Jeroen S
 * Coloured squares ignoring only applies to building, not solving
 * Adjusted several colour assignments
 */

package mazeAssignment;

import java.awt.*;

/**
 * MazeGraph, responsible for giving a visual representation
 * of the maze.
 * Extends from JPanel. To use, initialize with the Maze and 
 * place on an appropriate window. Call repaint() after
 * every update of the Maze to refresh this on the screen.
 *
 * @author: jeroen, jeroen, marcel en teun
 */
public class MazeGraphClassic extends MazeGraph {

	public static final int ELEMENT_WIDTH = 16;		//Feel free to adjust.

	public static final long serialVersionUID = 1L;
	
	public MazeGraphClassic(Maze pMaze)
	{
		super(pMaze);
	}
	
	public void paintComponent(Graphics g)
	{
		//Clears the panel
		super.paintComponent(g);
		
		//Retrieve sizes for ease of access later
		int mazesizex = maze.getSizeX();
		int mazesizey = maze.getSizeY();
		int mywidth = this.getWidth()-2;
		int myheight = this.getHeight()-2;
		
		for(int x = 0; x < mazesizex; x++)
		{
			for(int y = 0; y < mazesizey; y++)
			{
				// Drawing coloured squares on the maze.
				// This can be distracting, and thus optional
				if(mDrawBuildColors || maze.getSolveState(x, y) != Maze.SOLVE_UNVISITED)
				{
					// Set colour based on status
					// (Colours chosen arbitrarily)
					if(maze.getSolveState(x, y) == Maze.SOLVE_UNVISITED)
					{
						switch(maze.getBuildState(x, y))
						{
							case 0:
								g.setColor(Color.GRAY);
								break;
							case 1:
								g.setColor(Color.YELLOW);
								break;
							case 2:
								g.setColor(Color.ORANGE);
								break;
							case 3:
								g.setColor(Color.CYAN);
								break;
							case 4:
								g.setColor(Color.MAGENTA);
								break;
						}
					} else {
						switch(maze.getSolveState(x, y))
						{
						case Maze.SOLVE_UNVISITED:
							// Not reached (handled as default case)
							g.setColor(Color.WHITE);
							break;
						case Maze.SOLVE_START:
							g.setColor(Color.RED);
							break;
						case Maze.SOLVE_END:
							g.setColor(Color.GREEN);
							break;
						case Maze.SOLVE_VISITED:
							g.setColor(Color.BLACK);
							break;
						case Maze.SOLVE_INVALID:
							g.setColor(Color.BLUE);
						}
						
					}
					
					// Lack of parentheses intentional, to 
					// force higher accuracy
					// Size (arg 3 + 4) includes a 1 pixel border
					g.fillRect(x * mywidth / mazesizex,
						y * myheight / mazesizey, 
						mywidth / mazesizex,
						myheight / mazesizey);
				}
				
				//Draw walls
				g.setColor(Color.BLACK);
				
				if(maze.getNorth(x, y))
				{
					g.drawLine(x*mywidth / mazesizex, 
					  y*myheight / mazesizey, 
					  (x+1)*mywidth/mazesizex,
					  y*myheight / mazesizey);
				}

				if(maze.getWest(x, y))
				{
					g.drawLine(x*mywidth / mazesizex, 
					  y*myheight / mazesizey, 
					  x*mywidth/mazesizex,
					  (y+1)*myheight / mazesizey);
				}

				if(maze.getSouth(x, y))
				{
					g.drawLine(x*mywidth / mazesizex, 
					  (y+1)*myheight / mazesizey, 
					  (x+1)*mywidth/mazesizex,
					  (y+1)*myheight / mazesizey);
				}

				if(maze.getEast(x, y))
				{
					g.drawLine((x+1)*mywidth / mazesizex, 
					  y*myheight / mazesizey, 
					  (x+1)*mywidth/mazesizex,
					  (y+1)*myheight / mazesizey);
				}
			}
		}
	}
}
